 package srdb.migration.dbhandler.redwood;
 
   
 import java.sql.SQLException;
import org.apache.log4j.Logger;

import srdb.migration.MigrationToolkit;
import srdb.migration.Utility;
import srdb.migration.common.IMTKConnection;
import srdb.migration.schema.metadata.Column;
import srdb.migration.schema.metadata.Column.DataType;
 
 public class NZTransformDDL extends EDBTransformDDL
 {
   protected String getColumnLine(Column column)
   {
     String str = "";
     String colName = column.getName();
 
     if ((!column.isCaseSensitive()) && (colName.indexOf('#') >= 0)) {
       colName = "\"" + colName.toLowerCase() + "\"";
     }
 
     str = str + getIndent() + colName;
 
     String customType = null;
 
     if ((customType = super.getCustomColType(column.getTableName(), column.getName())) != null) {
       str = str + " " + customType;
     } else {
       if (column.isRowID())
       {
         str = str + " " + "VARCHAR";
       } else if (column.isInterval())
         str = str + " " + "INTERVAL";
       else if (column.isTimeStamp())
       {
         str = str + " TIMESTAMP";
       } else if (column.getDataTypeString().equalsIgnoreCase("NUMBER"))
         str = str + " NUMERIC";
       else if (column.getDataTypeString().equalsIgnoreCase("NCHAR"))
       {
         str = str + " NCHAR";
       } else if (column.getDataTypeString().equalsIgnoreCase("NVARCHAR2"))
       {
         str = str + " NVARCHAR";
       } else if (column.isVarchar())
       {
         try
         {
           String dataTypeStr = column.getDataTypeString();
           String prm_NLS_CHARACTERSET_Value = MigrationToolkit.getInstance().getSrcConn().getDBServerParamValue("NLS_CHARACTERSET");
           if ((prm_NLS_CHARACTERSET_Value != null) && (!prm_NLS_CHARACTERSET_Value.equalsIgnoreCase("WE8ISO8859P15")) && (!prm_NLS_CHARACTERSET_Value.equalsIgnoreCase("US7ASCII")))
           {
             if (dataTypeStr.equalsIgnoreCase("VARCHAR2"))
               str = str + " NVARCHAR";
             else if (dataTypeStr.equalsIgnoreCase("CHAR"))
               str = str + " NCHAR";
             else {
               str = str + " " + dataTypeStr;
             }
           }
           else if (dataTypeStr.equalsIgnoreCase("VARCHAR2"))
             str = str + " VARCHAR";
           else
             str = str + " " + dataTypeStr;
         }
         catch (SQLException sqle)
         {
           Utility.getLogger().warn("NLS_CHARACTERSET value could not be found. Reason: " + sqle.getMessage());
 
           str = str + " " + column.getDataTypeString();
         }
       }
       else str = str + " " + column.getDataTypeString();
 
       if ((column.getDataType() == Column.DataType.VARCHAR) || (column.getDataType() == Column.DataType.NVARCHAR)) {
         str = str + "(" + column.getLength() + ")";
       }
       if ((column.getDataType() == Column.DataType.INTEGER) || (column.getDataType() == Column.DataType.NUMERIC)) {
         if (column.getPrecision() > 0) {
           str = str + "(" + column.getPrecision();
           if (column.getScale() > 0)
             str = str + "," + column.getScale();
           str = str + ")";
         } else if (column.getDataTypeString().equalsIgnoreCase("NUMBER")) {
           str = str + "(38)";
         }
       }
 
     }
 
     if (column.getDefaultClause() != null) {
       str = str + " DEFAULT " + column.getDefaultClause();
     }
 
     if (!column.isNullable()) {
       str = str + " NOT NULL";
     }
     return str;
   }
 }

/* 

 * 
 */